@extends('layouts.app', ['active' => 2])

@section('title')管理员列表 -
@endsection
@section('content')

            <div class="panel panel-default">
                <div class="panel-heading"><i class="fa fa-align-justify"></i> 管理员列表
                    @include('user.menu',['active' => 2])
                </div>
                <div class="panel-body">
                  <div class="row" style="margin-bottom:10px">
                    <div class="col-md-6 text-left">
                      <form class="form-inline" action="{{ url('person/') }}" method="POST">
                        <div class="form-group">
                          <label class="sr-only" for="exampleInputPassword3">手机号</label>
                          <!--<select class="form-control" id="batch_type">
                            <option value="#delete_modal">操作</option>
                          </select>-->
                        </div>
                       <!-- <button type="button" data-toggle="modal" class="btn btn-default" data-action="" data-target="#delete_modal">应用</button>-->
                      </form>
                    </div>

                      <div class="col-md-6 text-right">
                        <form class="form-inline" action="" method="GET">
                          <div class="form-group">
                            <label class="sr-only" for="keyword">手机号</label>
                            <input type="text" class="form-control input-sm" name="keyword" id="keyword" placeholder="账号 | 邮箱">
                          </div>
                          <button type="submit" class="btn btn-primary btn-sm" title="搜索"><i class="fa fa-search" aria-hidden="true"></i></button>
                        </form>
                      </div>
                  </div>

                  <table class="table table-hover table-border table-condensed table-striped table-bordered">
                        <thead class="">
                          <tr>
                            <th><input type="checkbox" id="select_all"/></th>
                            <th>账号</th>
                            <th>邮箱</th>
                            <th>注册时间</th>
                            <th>最后登录时间</th>
                            <th style="width:160px;text-align:center">操作</th>
                              <th >状态</th>
                          </tr>
                        </thead>
                        <tbody>
                          @foreach ($users as $user)
                          <tr>
                            <td><input type="checkbox" name="ids" value="{{ $user->id }}"/></td>
                            <td>{{ $user->name }}</td>
                            <td>{{ $user->email }}</td>
                            <td>{{ $user->created_at }}</td>
                            <td>{{ $user->updated_at }}</td>
                            <td style="text-align: center">
                                    <a href="{{ url('user/'.$user->id.'/edit') }}" title="修改密码"><i aria-hidden="true" class="fa fa-pencil-square-o"></i></a>
                            </td>
                              <td>
                                  @if ($user->is_forbided == 0)
                                      @if ($user->id != 1)
                                  <a href="" class="forbid_link" style="color:#5cb85c;font-weight:bold"  title="正常">✔</a>
                                  <form action="user/forbid" class="forbid_form"  method="POST" style="display: none;" id="fborbid_form_{{$user->id}}">
                                      {{ csrf_field() }}
                                      <input type="hidden" name="id" id="fborbid_{{$user->id}}" value="{{$user->id}}">
                                      <input type="hidden" name="type" id="fborbid_type_{{$user->id}}" value="1"/>
                                  </form>
                                      @endif
                                  @else


                                  <a href="" class="forbid_link" style="color:#c12e2a;font-weight:bold" title="被禁用" >X</a>
                                      <form action="user/forbid" class="forbid_form"  method="POST" style="display: none;" id="fborbid_form_{{$user->id}}">
                                          {{ csrf_field() }}
                                          <input type="hidden" name="id" id="fborbid_{{$user->id}}" value="{{$user->id}}"/>
                                          <input type="hidden" name="type" id="fborbid_type_{{$user->id}}" value="0"/>
                                      </form>
                                  @endif
                              </td>
                          </tr>
                          @endforeach
                        </tbody>
                      </table>
                      {{ $users->links() }}
                </div>
            </div>



@endsection

@section('script')
<script>
  $(function(){
    $('#batch_delete').click(function(){
        var ids = [];
        $("input[name='ids']").each(function() {
            if ($(this).prop('checked') == true) {
                ids.push($(this).val());
            }
        });
        ids = ids.join(",");
        if (ids == '') {
            alert('请至少选择一个人员');
            return false;
        }

    });
    $('#select_all').change(function(){
      //alert($(this).prop("checked"));
      $("input[name='ids']").prop("checked", $(this).prop("checked"));
        var ids = [];
        $("input[name='ids']").each(function() {
            if ($(this).prop('checked') == true) {
                ids.push($(this).val());
            }
        });
        ids = ids.join(",");
        //alert(ids);
        $('#batch_delete').attr("data-action", "{{ url('person') }}/" + ids);



    });
      $("input[name='ids']").change(function(){
          var ids = [];
          $("input[name='ids']").each(function() {
              if ($(this).prop('checked') == true) {
                  ids.push($(this).val());
              }
          });
          ids = ids.join(",");
          //alert(ids);
          $('#batch_delete').attr("data-action", "{{ url('person') }}/" + ids);

      });

      // 禁用管理员用户
      $(".forbid_link").click(function(){
          //$("p").slideToggle();
          $(this).next().submit();
          return false;
      });






  });

</script>
@endsection
